#include "Log.hpp"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h> //struct sockaddr_in
#include <arpa/inet.h>
#include <string>
#include <strings.h> //bzero

class Inet_Addr
{
private:

public:
    Inet_Addr() = default;

    Inet_Addr(const sockaddr_in& addr) //n->s
    :_addr(addr)
    {
        _port = ntohs(addr.sin_port);//网络字节序 -> 主机字节序
        _ip = inet_ntoa(addr.sin_addr);//4byte -> 点分十进制的字符串, 2.网~ -> 主~
    }

    const struct sockaddr_in& get_addr() const
    {
        return _addr;
    }
    uint16_t get_port() const
    {
        return _port;
    }

    const std::string& get_ip() const
    {
        return _ip;
    }

    bool operator==(const Inet_Addr& peer) const
    {
        if(_port == peer._port && _ip == peer._ip)
            return true;
        return false;
    }

private:
    struct sockaddr_in _addr;
    uint16_t _port;
    std::string _ip;
};